﻿using PowerTestController.View;
using PowerTestController.ViewModes;
using HandyControl.Controls;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Win32;
using System.Configuration;
using System.Data;
using System.Diagnostics;
using System.Windows;
using PowerTestController.Communication;

namespace PowerTestController
{
    /// <summary>
    /// Interaction logic for App.xaml
    /// </summary>
    public partial class App : Application
    {
        public IServiceProvider Services { get; }
        public static new App Current => (App)Application.Current;

        public App()
        {
            Services = ConfigureServices();
        }

        private IServiceProvider? ConfigureServices()
        {
            var container = new ServiceCollection();
            container
                .AddSingleton<SerialPortCommunication>()
                .AddSingleton<MainViewModel>()
                .AddSingleton(
                    sp => new MainWindow { DataContext = sp.GetRequiredService<MainViewModel>() }
                )
                //.AddSingleton<SerialPortViewModel>()
                //.AddSingleton(
                //    sp =>
                //        new SerialPortView
                //        {
                //            DataContext = sp.GetRequiredService<SerialPortViewModel>()
                //        }
                //)
                ;
            return container.BuildServiceProvider();
        }
        protected override void OnStartup(StartupEventArgs e)
        {
            MainWindow = Services.GetRequiredService<MainWindow>();
            MainWindow.Show();
        }
    }
}
